package Classic150;

public class x的平方根 {
    /*
        二分查找
     */
    public int mySqrt(int x) {
        int left = 1, right = x;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (mid < x / mid) left = mid + 1;
            else if (mid > x / mid) right = mid - 1;
            else return mid;
        }
        return right;
    }
}
